<template>
  <div v-if="isComplete">
    <a-button disabled style="border-radius: 3px">
      悬赏已完成
    </a-button>
  </div>
  <div v-else>
    <a-button style="border-radius: 3px" @click="complete">
      结束悬赏
    </a-button>
  </div>
</template>

<script>
import {ref, reactive, defineComponent} from "vue";
import {get, put, post, tip, del} from "@/common";
import {message} from "ant-design-vue";

export default {
  name: "CompleteReward",
  props: {
    postID: Number,
    userID: Number,
  },
  setup(props, {emit}) {
    const scoreEntity = reactive({
      postID: props.postID,
      userID: props.userID,
      num: null,
      mark: null,
      isCheck: null
    });
    const isComplete = ref({});

    const checkIsComplete = () => {
      get("/score/checkIsComplete",scoreEntity).then((res) => {
        isComplete.value = res.data;
      })
    };
    checkIsComplete();

    const complete = () => {
      post("/score/complete", scoreEntity).then((res) => {
        message.success("结束悬赏成功!");
        checkIsComplete();
      })
    };
    return {
      scoreEntity,
      isComplete,
      complete,
      checkIsComplete,
    };
  },
}
</script>

<style scoped>

</style>